home *** CD-ROM | disk | FTP | other *** search
/ PC Home 49 / PC_Home_Issue_49.iso / lldemo / lldemo.shr / ROSETTA.EXE / ROSETTA.DXR / 00579_utility scripts.ls < prev    next >
Encoding:
Text File  |  1996-06-24  |  13.0 KB  |  422 lines

  1. global gStackLevel, gStack, gDebug
  2.  
  3. on head str, x
  4.   if x > 0 then
  5.     return char 1 to x of str
  6.   else
  7.     if x < 0 then
  8.       return char 1 to length(str) + x of str
  9.     else
  10.       return EMPTY
  11.     end if
  12.   end if
  13. end
  14.  
  15. on tail str, x
  16.   if x > 0 then
  17.     return char length(str) - x + 1 to length(str) of str
  18.   else
  19.     if x < 0 then
  20.       return char -x + 1 to length(str) of str
  21.     else
  22.       return EMPTY
  23.     end if
  24.   end if
  25. end
  26.  
  27. on pad n
  28.   if n < 10 then
  29.     return "0" & string(n)
  30.   else
  31.     return string(n)
  32.   end if
  33. end
  34.  
  35. on waitTicks t
  36.   set endTicks to the ticks + t
  37.   repeat while the ticks < endTicks
  38.     nothing()
  39.   end repeat
  40. end
  41.  
  42. on doToolClick which
  43.   set x to the mouseH
  44.   set y to the mouseV
  45.   set numTools to the number of lines in the text of cast which
  46.   repeat with i = 1 to numTools
  47.     set toolLine to line i of the text of cast which
  48.     if withinBox(item 1 of toolLine, item 2 of toolLine, item 3 of toolLine, item 4 of toolLine, x, y) then
  49.       if item 6 of toolLine <> "0" then
  50.         setOverlayPuppet(value(item 1 of toolLine), value(item 2 of toolLine), value(item 6 of toolLine))
  51.         updateStage()
  52.         if value(item 7 of toolLine) <> 0 then
  53.           clickRoutine(item 5 of toolLine)
  54.           if value(item 7 of toolLine) = 1 then
  55.             repeat while the mouseDown
  56.             end repeat
  57.           end if
  58.           hideOverlay()
  59.         else
  60.           hideOverlay()
  61.           clickRoutine(item 5 of toolLine)
  62.         end if
  63.       else
  64.         clickRoutine(item 5 of toolLine)
  65.       end if
  66.       exit repeat
  67.     end if
  68.   end repeat
  69. end
  70.  
  71. on clickRoutine pr
  72.   global gHasPressed
  73.   set command to word 1 of pr
  74.   set param to word 2 of pr
  75.   if command = "adjTime" then
  76.     adjTime(param)
  77.   else
  78.     if command = "go" then
  79.       do("go " && param)
  80.     else
  81.       if command = "giveResponse" then
  82.         set gHasPressed to 0
  83.         giveResponse(value(param))
  84.       else
  85.         if command = "goMenu" then
  86.           repeat while the mouseDown
  87.           end repeat
  88.           goMenu()
  89.         else
  90.           if command = "doRecord" then
  91.             doRecord()
  92.           else
  93.             if command = "doPlayRecord" then
  94.               doPlayRecord()
  95.             else
  96.               if command = "changeScreen" then
  97.                 changeScreen(value(param))
  98.               else
  99.                 if command = "goControls" then
  100.                   goControls()
  101.                 else
  102.                   if command = "toggleBrowse" then
  103.                     toggleBrowse()
  104.                   else
  105.                     if command = "toggleRun" then
  106.                       toggleRun()
  107.                     else
  108.                       if command = "pickYeah" then
  109.                         pickYeah(value(param))
  110.                       else
  111.                         if command = "pickNo" then
  112.                           pickNo(value(param))
  113.                         else
  114.                           if command = "chooseMode" then
  115.                             chooseMode(param)
  116.                           else
  117.                             if command = "toggleScore" then
  118.                               toggleScore()
  119.                             else
  120.                               if command = "adjTime" then
  121.                                 adjTime(param)
  122.                               else
  123.                                 if command = "adjVolume" then
  124.                                   adjVolume(param)
  125.                                 else
  126.                                   if command = "setVolume" then
  127.                                     setVolume(the mouseV)
  128.                                   else
  129.                                     alert("Illegal command: " & pr)
  130.                                     halt()
  131.                                   end if
  132.                                 end if
  133.                               end if
  134.                             end if
  135.                           end if
  136.                         end if
  137.                       end if
  138.                     end if
  139.                   end if
  140.                 end if
  141.               end if
  142.             end if
  143.           end if
  144.         end if
  145.       end if
  146.     end if
  147.   end if
  148. end
  149.  
  150. on inChallenge
  151.   global gScreenMode
  152.   return getaProp(gScreenMode, #SPECIAL) = #RUN
  153. end
  154.  
  155. on pictMode
  156.   global gScreenMode
  157.   if getaProp(gScreenMode, #PCTCHAL) <> #NONE then
  158.     return #challenge
  159.   else
  160.     if getaProp(gScreenMode, #PCTRESP) <> #NONE then
  161.       return #response
  162.     else
  163.       return #notUsed
  164.     end if
  165.   end if
  166. end
  167.  
  168. on translateMode mode
  169.   global gMode, gScreenMode
  170.   set gMode to mode
  171.   if mode = "122" then
  172.     set gScreenMode to [#SNDCHAL: #UPLEFT, #TXTCHAL: #top, #PCTCHAL: #NONE, #SCREEN: #TYPE1, #SNDRESP: #NONE, #TXTRESP: #NONE, #PCTRESP: #YES, #SPECIAL: #RUN, #mode: "1"]
  173.   else
  174.     if mode = "120" then
  175.       set gScreenMode to [#SNDCHAL: #UPLEFT, #TXTCHAL: #NONE, #PCTCHAL: #NONE, #SCREEN: #TYPE1, #SNDRESP: #NONE, #TXTRESP: #NONE, #PCTRESP: #YES, #SPECIAL: #RUN, #mode: "2"]
  176.     else
  177.       if mode = "102" then
  178.         set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #top, #PCTCHAL: #NONE, #SCREEN: #TYPE1, #SNDRESP: #NONE, #TXTRESP: #NONE, #PCTRESP: #YES, #SPECIAL: #RUN, #mode: "3"]
  179.       else
  180.         if mode = "121" then
  181.           set gScreenMode to [#SNDCHAL: #UPLEFT, #TXTCHAL: #NONE, #PCTCHAL: #NONE, #SCREEN: #TYPE1, #SNDRESP: #NONE, #TXTRESP: #ONPCT, #PCTRESP: #YES, #SPECIAL: #RUN, #mode: "4"]
  182.         else
  183.           if mode = "112" then
  184.             set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #top, #PCTCHAL: #NONE, #SCREEN: #TYPE1, #SNDRESP: #ONPCT, #TXTRESP: #NONE, #PCTRESP: #YES, #SPECIAL: #RUN, #mode: "5"]
  185.           else
  186.             if mode = "211" then
  187.               set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #NONE, #PCTCHAL: #YES, #SCREEN: #TYPE2, #SNDRESP: #ONTXT, #TXTRESP: #ALONE, #PCTRESP: #NONE, #SPECIAL: #RUN, #mode: "6"]
  188.             else
  189.               if mode = "210" then
  190.                 set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #NONE, #PCTCHAL: #YES, #SCREEN: #TYPE2, #SNDRESP: #ONTXT, #TXTRESP: #NONE, #PCTRESP: #NONE, #SPECIAL: #RUN, #mode: "7"]
  191.               else
  192.                 if mode = "201" then
  193.                   set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #NONE, #PCTCHAL: #YES, #SCREEN: #TYPE2, #SNDRESP: #NONE, #TXTRESP: #ALONE, #PCTRESP: #NONE, #SPECIAL: #RUN, #mode: "8"]
  194.                 else
  195.                   if mode = "221" then
  196.                     set gScreenMode to [#SNDCHAL: #ONPCT, #TXTCHAL: #NONE, #PCTCHAL: #YES, #SCREEN: #TYPE2, #SNDRESP: #NONE, #TXTRESP: #ALONE, #PCTRESP: #NONE, #SPECIAL: #RUN, #mode: "9"]
  197.                   else
  198.                     if mode = "212" then
  199.                       set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #ONPCT, #PCTCHAL: #YES, #SCREEN: #TYPE2, #SNDRESP: #ONTXT, #TXTRESP: #NONE, #PCTRESP: #NONE, #SPECIAL: #RUN, #mode: "10"]
  200.                     else
  201.                       if mode = "021" then
  202.                         set gScreenMode to [#SNDCHAL: #UPLEFT, #TXTCHAL: #NONE, #PCTCHAL: #NONE, #SCREEN: #TYPE2, #SNDRESP: #NONE, #TXTRESP: #ALONE, #PCTRESP: #NONE, #SPECIAL: #RUN, #mode: "11"]
  203.                       else
  204.                         if mode = "012" then
  205.                           set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #top, #PCTCHAL: #NONE, #SCREEN: #TYPE2, #SNDRESP: #ONTXT, #TXTRESP: #NONE, #PCTRESP: #NONE, #SPECIAL: #RUN, #mode: "12"]
  206.                         else
  207.                           if mode = "111" then
  208.                             set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #NONE, #PCTCHAL: #NONE, #SCREEN: #TYPE1, #SNDRESP: #ONPCT, #TXTRESP: #ONPCT, #PCTRESP: #YES, #SPECIAL: #BROWSE, #mode: "A"]
  209.                           else
  210.                             if mode = "110" then
  211.                               set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #NONE, #PCTCHAL: #NONE, #SCREEN: #TYPE1, #SNDRESP: #ONPCT, #TXTRESP: #NONE, #PCTRESP: #YES, #SPECIAL: #BROWSE, #mode: "B"]
  212.                             else
  213.                               if mode = "011" then
  214.                                 set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #NONE, #PCTCHAL: #NONE, #SCREEN: #TYPE1, #SNDRESP: #ONPCT, #TXTRESP: #ONPCT, #PCTRESP: #NONE, #SPECIAL: #BROWSE, #mode: "C"]
  215.                               else
  216.                                 if mode = "110dict" then
  217.                                   set gScreenMode to [#SNDCHAL: #NONE, #TXTCHAL: #NONE, #PCTCHAL: #NONE, #SCREEN: #TYPE1, #SNDRESP: #ONPCT, #TXTRESP: #NONE, #PCTRESP: #YES, #SPECIAL: #DICT, #mode: " "]
  218.                                 else
  219.                                   alert("Illegal mode given: " & mode)
  220.                                   halt()
  221.                                 end if
  222.                               end if
  223.                             end if
  224.                           end if
  225.                         end if
  226.                       end if
  227.                     end if
  228.                   end if
  229.                 end if
  230.               end if
  231.             end if
  232.           end if
  233.         end if
  234.       end if
  235.     end if
  236.   end if
  237.   sort(gScreenMode)
  238. end
  239.  
  240. on isBrowse
  241.   global gScreenMode
  242.   set SPECIAL to getaProp(gScreenMode, #SPECIAL)
  243.   if (SPECIAL = #BROWSE) or (SPECIAL = #DICT) then
  244.     return 1
  245.   else
  246.     return 0
  247.   end if
  248. end
  249.  
  250. on isDict
  251.   global gScreenMode
  252.   if getaProp(gScreenMode, #SPECIAL) = #DICT then
  253.     return 1
  254.   else
  255.     return 0
  256.   end if
  257. end
  258.  
  259. on withinBox l, t, r, b, x, y
  260.   return (x >= l) and (x <= r) and (y >= t) and (y <= b)
  261. end
  262.  
  263. on modeNum mode
  264.   return value(char 1 of mode) + (value(char 2 of mode) * 3) + (value(char 3 of mode) * 9) + 1
  265. end
  266.  
  267. on clearstuff
  268.   repeat with i = 0 to 39
  269.     set the text of cast (345 + i) to "@"
  270.   end repeat
  271.   repeat with i = 0 to 7
  272.     set the fileName of cast (449 + i) to "BLANK.PCT"
  273.   end repeat
  274.   repeat with i = 0 to 3
  275.     set the text of cast (49 + i) to " "
  276.     set the text of cast (113 + i) to " "
  277.   end repeat
  278.   set the text of cast 2 to " "
  279.   set the text of cast 105 to " "
  280.   set the text of cast 106 to " "
  281.   set the text of cast 42 to " "
  282.   set the text of cast 228 to " "
  283.   put " " into field "login name"
  284.   put " " into field "Password"
  285.   put " " into field "Announce Text"
  286.   clearGlobals()
  287. end
  288.  
  289. on formatTime tics
  290.   set mins to tics / 3600
  291.   set hrs to mins / 60
  292.   set mins to mins mod 60
  293.   if mins < 10 then
  294.     set mins to "0" & mins
  295.   end if
  296.   set secs to tics mod 3600 / 60
  297.   if secs < 10 then
  298.     set secs to "0" & secs
  299.   end if
  300.   if hrs > 9 then
  301.     return "9:59:59"
  302.   else
  303.     return string(hrs) & ":" & string(mins) & ":" & string(secs)
  304.   end if
  305. end
  306.  
  307. on randMode
  308.   global gMode
  309.   set theModes to "122,122,120,120,102,102,211,211,210,210,201,201,212,012,021,221,112,121"
  310.   set newMode to item random(18) of theModes
  311.   repeat while newMode = gMode
  312.     set newMode to item random(18) of theModes
  313.   end repeat
  314.   return newMode
  315. end
  316.  
  317. on randPage currPage
  318.   global gNumPages, gRandPageOrder, gRandPageIndex
  319.   if gRandPageIndex = 0 then
  320.     set gRandPageOrder to EMPTY
  321.     repeat with i = 1 to 10
  322.       set r to random(gNumPages) - 1
  323.       repeat while gRandPageOrder contains string(r)
  324.         set r to random(gNumPages) - 1
  325.       end repeat
  326.       put string(r) & " " after gRandPageOrder
  327.     end repeat
  328.   end if
  329.   set gRandPageIndex to gRandPageIndex + 1
  330.   set nPage to word gRandPageIndex of gRandPageOrder
  331.   if gRandPageIndex = 10 then
  332.     set gRandPageIndex to 0
  333.   end if
  334.   return integer(nPage) + 1
  335. end
  336.  
  337. on randomize
  338.   set the randomSeed to the ticks mod 262144
  339. end
  340.  
  341. on ChapStr2Unit s
  342.   return value(char 1 to 2 of word 2 of s)
  343. end
  344.  
  345. on ChapStr2Chap s
  346.   return value(char 4 to 5 of word 2 of s)
  347. end
  348.  
  349. on ChapStr2Language s
  350.   return word 1 of s
  351. end
  352.  
  353. on makeChapStr language, unit, chapter
  354.   return language & " " & pad(unit) & "-" & pad(chapter)
  355. end
  356.  
  357. on initBroadcast
  358.   set gStackLevel to 0
  359.   set gStack to []
  360. end
  361.  
  362. on broadcast str
  363.   if gDebug = 0 then
  364.     return 
  365.   else
  366.     if gDebug = #call then
  367.       set ps to string(the frame)
  368.       repeat with i = 0 to gStackLevel
  369.         put "  " after ps
  370.       end repeat
  371.       put ps & str
  372.       set gStackLevel to gStackLevel + 1
  373.       add(gStack, word 1 of str)
  374.     else
  375.       if gDebug = #performance then
  376.         set gStackLevel to gStackLevel + 1
  377.         add(gStack, word 1 of str && the ticks)
  378.       end if
  379.     end if
  380.   end if
  381. end
  382.  
  383. on popBroad str
  384.   if gDebug = 0 then
  385.     return 
  386.   else
  387.     if gDebug = #call then
  388.       set match to getLast(gStack)
  389.       if match <> str then
  390.         put "**** Mismatched stack: " & str && match
  391.       end if
  392.       deleteAt(gStack, count(gStack))
  393.       set gStackLevel to gStackLevel - 1
  394.       if gStackLevel < 0 then
  395.         put "**** Stack level is negative!" && gStackLevel
  396.       else
  397.         nothing()
  398.       end if
  399.     else
  400.       if gDebug = #performance then
  401.         set t to the ticks
  402.         set match to getLast(gStack)
  403.         if word 1 of match <> str then
  404.           put "**** Mismatched stack: " & str && match
  405.         end if
  406.         deleteAt(gStack, count(gStack))
  407.         set ps to EMPTY
  408.         repeat with i = 0 to gStackLevel
  409.           put "  " after ps
  410.         end repeat
  411.         put ps & str && t - value(word 2 of match) && t mod 4096
  412.         set gStackLevel to gStackLevel - 1
  413.         if gStackLevel < 0 then
  414.           put "**** Stack level is negative!" && gStackLevel
  415.         else
  416.           nothing()
  417.         end if
  418.       end if
  419.     end if
  420.   end if
  421. end
  422.